<?

include_once 'library/smarty/src/Smarty.class.php';

class Smutty_Template extends Smarty {

	/**
	 *  contructor.  sets up our customised version
	 *  of the smarty template.
	 *
	 */

	function Smutty_Template() {

		// this is a utility class for plugins so make
		// sure it's loaded.
		Smutty_Main::loadClass( 'Smutty_Smarty' );

		$this->compile_dir = 'application/cache';
		$this->template_dir = 'application/views/';
		$this->plugins_dir[] = 'library/smarty/plugins/'; // smutty plugins
		$this->plugins_dir[] = 'application/plugins/'; // app plugins
		$this->autoload_filters = array(
			'pre' => array( 'allow_assoc_attrs' )
		);

		$session = Smutty_Session::getInstance();

		// create the smutty variable
		$smutty = new stdclass();
		$smutty->session = $session;
		$smutty->user = $session->user;
		$smutty->smuttyUrl = Smutty_Utils::getSmuttyUrl();
		$smutty->baseUrl = Smutty_Utils::getBaseUrl();
		$this->assign( 'smutty', $smutty );

	}

	/**
	 *  displays a template.
	 *
	 */

	function display( $file ) {

		$router = Smutty_Router::getInstance();

		// try to use controller shortcut for filenames, if it
		// fails then fall back on the filename
		$path = strtolower($router->getControllerName()) . "/$file";
		if ( !file_exists("$this->template_dir$path") )
			$path = $file;

		parent::display( $path );

	}

	/**
	 *  this function loads another smarty plugin, specified
	 *  by type (function/modifier/etc...) and name.
	 *
	 *  @param [type] the plugin type
	 *  @param [name] the plugin name
	 *
	 */

	function depend( $type, $name ) {

		require_once $this->_get_plugin_filepath( $type, $name );

	}
}

?>